besw14b
program define bwealth
*************************
*** 1.1. Household Size
*************************

** Household Size = 1 * Head + .5 * Adult Member + .3 * Dependent_under18
**anyone NOT living in the HOUSE is not included 
gen adults = 1 if (profile_marital_statW14 == 3 | profile_marital_statW14 == 4 | profile_marital_statW14 == 5 | profile_marital_statW14 == 6) & sickElderlyInHouseW6_W14 == 0 // single, no adults dependents
replace adults = 2 if (profile_marital_statW14 == 1 | profile_marital_statW14 == 2 | profile_marital_statW14 == 7) & sickElderlyInHouseW6_W14 == 0 // married, partner etc
replace adults = 2 if (profile_marital_statW14 == 3 | profile_marital_statW14 == 4 | profile_marital_statW14 == 5 | profile_marital_statW14 == 6) & sickElderlyInHouseW6_W14 == 1 // single but adult dependent
replace adults = 3 if (profile_marital_statW14 == 1 | profile_marital_statW14 == 2 | profile_marital_statW14 == 7) & sickElderlyInHouseW6_W14 == 1 // married, partner + adult dependent

replace numChildrenW14 = 0 if numChildrenW14 == 111
 
gen error1 = 1 if numChildrenW14 == 0 & preschoolKidsInHouseW6_W14 == 1 
gen error2 = 1 if numChildrenW14 == 0 & schoolKidsInHouseW6_W14 == 1 
gen error3 = 1 if numChildrenW14 == 0 & noDependentsInHouseW6_W14 == 0 &  sickElderlyInHouseW6_W14 == 0 

drop if error1 == 1 | error2 == 1 | error3 == 1 
drop error1 error2 error3

gen kids = 0 if numChildrenW14 == 0 | (preschoolKidsInHouseW6_W14 == 0 & schoolKidsInHouseW6_W14 == 0) // if no kids below 18 in the house, i put 0 even if they have adult kids

replace kids = 1 if numChildrenW14 == 1 & preschoolKidsInHouseW6_W14 == 1 // 1 kid either in pre-school 
replace kids = 1 if numChildrenW14 == 1 & schoolKidsInHouseW6_W14 == 1 // or in school

replace kids = 2 if numChildrenW14 == 2 & preschoolKidsInHouseW6_W14 == 1 // 1 kid either in pre-school 
replace kids = 2 if numChildrenW14 == 2 & schoolKidsInHouseW6_W14 == 1 // or in school

replace kids = 3 if numChildrenW14 == 3 & preschoolKidsInHouseW6_W14 == 1 // 1 kid either in pre-school 
replace kids = 3 if numChildrenW14 == 3 & schoolKidsInHouseW6_W14 == 1 // or in school

replace kids = 4 if numChildrenW14 == 4 & preschoolKidsInHouseW6_W14 == 1 // 1 kid either in pre-school 
replace kids = 4 if numChildrenW14 == 4 & schoolKidsInHouseW6_W14 == 1 // or in school

replace kids = 5 if numChildrenW14 == 5 & preschoolKidsInHouseW6_W14 == 1 // 1 kid either in pre-school 
replace kids = 5 if numChildrenW14 == 5 & schoolKidsInHouseW6_W14 == 1 // or in school

replace kids = 6 if numChildrenW14 == 6 & preschoolKidsInHouseW6_W14 == 1 // 1 kid either in pre-school 
replace kids = 6 if numChildrenW14 == 6 & schoolKidsInHouseW6_W14 == 1 // or in school


*household size

gen HHsize = 1 if adults == 1 & kids == 0 // single person, no kids
replace HHsize = 1.3 if adults == 1 & kids == 1 // single person, 1 kid
replace HHsize = 1.6 if adults == 1 & kids == 2 // single person, 2 kid
replace HHsize = 1.9 if adults == 1 & kids == 3 // single person, 3 kid
replace HHsize = 2.2 if adults == 1 & kids == 4 // single person, 4 kid
replace HHsize = 2.5 if adults == 1 & kids == 5 // single person, 5 kid
replace HHsize = 2.8 if adults == 1 & kids == 6 // single person, >5 kid

replace HHsize = 1.5 if adults == 2 & kids == 0 // couple or 1 adult + 1 adult dependent, no kids
replace HHsize = 1.8 if adults == 2 & kids == 1 // couple, 1 kid
replace HHsize = 2.1 if adults == 2 & kids == 2 // couple, 2 kid
replace HHsize = 2.4 if adults == 2 & kids == 3 // couple, 3 kid
replace HHsize = 2.7 if adults == 2 & kids == 4 // couple, 4 kid
replace HHsize = 3 if adults == 2 & kids == 5 // couple, 5 kid
replace HHsize = 3.3 if adults == 2 & kids == 6 // couple, >5 kid

replace HHsize = 2 if adults == 3 & kids == 0 // couple and 1 adult dependent, no kids
replace HHsize = 2.3 if adults == 3 & kids == 1 // couple, 1 kid
replace HHsize = 2.6 if adults == 3 & kids == 2 // couple, 2 kid
replace HHsize = 2.9 if adults == 3 & kids == 3 // couple, 3 kid
replace HHsize = 3.2 if adults == 3 & kids == 4 // couple, 4 kid
replace HHsize = 3.5 if adults == 3 & kids == 5 // couple, 5 kid
replace HHsize = 3.8 if adults == 3 & kids == 6 // couple, >5 kid


*********************
*1.2. Income Measure 
*********************

gen mean_income = 2500 if profile_gross_householdW14 == 1
replace mean_income = 7499.5 if profile_gross_householdW14 == 2
replace mean_income = 12499.5 if profile_gross_householdW14 == 3
replace mean_income = 17499.5 if profile_gross_householdW14 == 4
replace mean_income = 22499.5 if profile_gross_householdW14 == 5
replace mean_income = 27499.5 if profile_gross_householdW14 == 6
replace mean_income = 32499.5 if profile_gross_householdW14 == 7
replace mean_income = 37499.5 if profile_gross_householdW14 == 8
replace mean_income = 42499.5 if profile_gross_householdW14 == 9
replace mean_income = 47499.5 if profile_gross_householdW14 == 10
replace mean_income = 54999.5 if profile_gross_householdW14 == 11
replace mean_income = 64999.5 if profile_gross_householdW14 == 12
replace mean_income = 84999.5 if profile_gross_householdW14 == 13
replace mean_income = 124999.5 if profile_gross_householdW14 == 14

*************************
*1.3. EQUIVALIZED INCOME
**************************
*1 if head, .5 addition, .3 for dependents <18

gen mean_HHincome = mean_income / HHsize


*********************
*CONSTRUCT WEALTH 
*********************

************
*1.5. Debt
************
replace  debtW14 = . if  debtW14 == 9999

gen mean_debt = 0 if debtW14 == 0  
replace mean_debt = 49.5 if debtAmtbW14 == 1
replace mean_debt = 299.5 if debtAmtbW14 == 2
replace mean_debt = 749.5 if debtAmtbW14 == 3
replace mean_debt = 1499.5 if debtAmtbW14 == 4
replace mean_debt = 2499.5 if debtAmtbW14 == 5
replace mean_debt = 3999.5 if debtAmtbW14 == 6
replace mean_debt = 7499.5 if debtAmtbW14 == 7
replace mean_debt = 12499.5 if debtAmtbW14 == 8
replace mean_debt = 17499.5 if debtAmtbW14 == 9
replace mean_debt = 24999.5 if debtAmtbW14 == 10
replace mean_debt = 34999.5 if debtAmtbW14 == 11
replace mean_debt = 44999.5 if debtAmtbW14 == 12
replace mean_debt = 62499.5 if debtAmtbW14 == 13
replace mean_debt = 87499.5 if debtAmtbW14 == 14
replace mean_debt = 124999.5 if debtAmtbW14 == 15
replace mean_debt = 174999.5 if debtAmtbW14 == 16


************
*1.6 Savings
************

qui tab savingsW14
replace savingsW14 = . if savingsW14 == 9999
 
gen mean_save = 0 if savingsW14 == 0 
replace mean_save = 49.5 if savingsAmtbW14 ==  1
replace mean_save = 299.5 if savingsAmtbW14 ==  2
replace mean_save = 749.5 if savingsAmtbW14 ==  3
replace mean_save = 1499.5 if savingsAmtbW14 ==  4
replace mean_save = 2499.5 if savingsAmtbW14 ==  5
replace mean_save = 3999.5 if savingsAmtbW14 ==  6
replace mean_save = 7499.5 if savingsAmtbW14 ==  7
replace mean_save = 12499.5 if savingsAmtbW14 == 8 
replace mean_save = 17499.5 if savingsAmtbW14 ==  9
replace mean_save = 24999.5 if savingsAmtbW14 == 10
replace mean_save = 34999.5 if savingsAmtbW14 == 11
replace mean_save = 44999.5 if savingsAmtbW14 == 12
replace mean_save = 62499.5 if savingsAmtbW14 == 13
replace mean_save = 87499.5 if savingsAmtbW14 == 14
replace mean_save = 124999.5 if savingsAmtbW14 == 15
replace mean_save = 174999.5 if savingsAmtbW14 == 16
 

************
*1.7 Rent
************
*Please estimate the proportion (%) of your household income, after tax, spent on your rent per month

replace rentPaymentW14 = . if  rentPaymentW14 == 9999
drop if homeOwnW14 == 4 & rentPaymentW14  == 0

gen monthly_mean_income = mean_income / 12
gen yearly_rent =  (rentPaymentW14* monthly_mean_income) * 12 /   100
replace yearly_rent = 0 if homeOwnW14 == 1 | homeOwnW14 == 2 


************
*1.7 Mortage
************
*Please estimate the proportion (%) of household income, after tax, spent on your mortgage per month:

replace mortgagePaymentW14 = . if mortgagePaymentW14 == 9999
drop if homeOwnW14 == 2 & mortgagePaymentW14  == 0 

gen yearly_mortgage = (mortgagePaymentW14 * monthly_mean_income) * 12 / 100
replace yearly_mortgage = 0 if homeOwnW14  == 1 | homeOwnW14 == 3 | homeOwnW14  == 4 | homeOwnW14 == 5 

*****************
*1.8 Home Value 
*****************

replace homeOwn = . if homeOwn == 9999
replace homeAmtb = . if homeAmtb == 9999

gen homevalue = 0 if homeOwnW14 == 3 | homeOwnW14 == 4 | homeOwnW14 == 5 // no asset is renting
replace homevalue = 24999.5 if homeAmtbW14 ==  1
replace homevalue = 74999.5 if homeAmtbW14 ==  2
replace homevalue = 124999.5 if homeAmtbW14 ==  3
replace homevalue = 174999.5 if homeAmtbW14 ==  4
replace homevalue = 224999.5 if homeAmtbW14 ==  5
replace homevalue = 274999.5 if homeAmtbW14 ==  6
replace homevalue = 349999.5 if homeAmtbW14 ==  7
replace homevalue = 449999.5 if homeAmtbW14 ==   8
replace homevalue = 549999.5 if homeAmtbW14 ==  9
replace homevalue = 649999.5 if homeAmtbW14 == 10
replace homevalue = 749999.5 if homeAmtbW14 == 11
replace homevalue = 849999.5 if homeAmtbW14 == 12
replace homevalue = 949999.5 if homeAmtbW14 == 13
end

bwealth

keep if mean_income !=. & mean_HHincome !=. & HHsize !=. & mean_debt!=. & ///
mean_save !=. & yearly_rent!=. & yearly_mortgage !=. & homevalue != .   

drop if leave == .  | al_scaleW14 == . | anyUniW14 == . | female == . | married == . |  ageW14 == . |  wkstat == . | onsAreaSupergroupW14 == . 

********************************************************************************


gen f_wealth = mean_save - mean_debt
gen p_wealth = homevalue


gen incomerent2 = mean_income - yearly_rent - yearly_mortgage

gen incomedisHH2 = incomerent2/HHsize
gen f_wealthHH = f_wealth / HHsize
gen p_wealthHH = p_wealth / HHsize

** creating standarized measures
egen z_income_disHH = std(incomedisHH2)
egen z_f_wealth = std(f_wealthHH)
egen z_p_wealth = std(p_wealthHH)


*************
* Figure B1
*************

preserve
gen poor2 = 1 if z_income_disHH <=0 & z_income_disHH <.
replace  poor2= 0 if z_income_disHH >0 & z_income_disHH <.

catplot poor2 homeOwnW14, ///
percent(poor2) ///
var1opts(label(labsize(small))) ///
var2opts(label(labsize(small)) relabel(`r(relabel)')) ///
ytitle("Percent of Respondents by Disposable Income (HH Adj)", size(small)) ///
blabel(bar, format(%4.1f)) ///
intensity(25) ///
asyvars legend(on order(1 "High" 2 "Low"))
graph export "$output/fig_b1.pdf",  replace
restore

*************
* Figure B2
*************

preserve
qui sum mean_save
gen meanS =  r(mean)

gen lowsave = 1 if mean_save >=0 & mean_save <= meanS
replace lowsave = 0 if mean_save >meanS & mean_save !=.

twoway (kdensity z_income_disHH if lowsave == 0 , color(orange)  )  ///
 (kdensity z_income_disHH if lowsave == 1, lpattern(solid) color(black) ), ///
 legend(order(1 "High Saving" 2 "Low Saving")) xtitle("HH Adjusted Disposable Income") ytitle("Density") 
graph export "$output/fig_b2.pdf", replace
restore

*************
* Figure B3
*************

preserve
qui sum mean_debt
gen meanD =  r(mean)

gen lowdebt = 1 if mean_debt >=0 & mean_debt <=meanD
replace lowdebt = 0 if mean_debt >meanD & mean_debt !=.

twoway (kdensity z_income_disHH if lowdebt == 0 , color(orange)  ) ///
 (kdensity z_income_disHH if lowdebt == 1,  lpattern(solid) color(black) ), ///
 legend(order(1 "High Debt" 2 "Low Debt")) xtitle("HH Adjusted Disposable Income") ytitle("Density")
graph export "$output/fig_b3.pdf", replace
restore

*************
* Figure C2
*************

********************************************************************************
** are leavers wealthier?

preserve
qui reg z_p_wealth leave, r
estimate store z_p_wealth
qui reg z_f_wealth leave, r
estimate store z_f_wealth

coefplot z_p_wealth z_f_wealth, xline(0) keep(leave) xline(0, lcolor(red) lstyle(solid)) msymbol(circle)   legend(off)  aseq swapnames  ///
coeflabels(z_p_wealth = "Property Wealth" z_f_wealth = "Financial Wealth") ///
 mfcolor(black) mlcolor (white) msize(2.5) ciopts(lpatt(solid)lcol(black)) xlabel(-.075  -.025 0 .025 .075) 
graph export "$output/fig_c2.pdf", replace

** mean not different, how about distributions? 

kdensity z_p_wealth if leave == 0, plot(kdensity z_p_wealth if leave == 1, lpattern("solid") lcolor("orange")) ///
	legend(label(1 "Remain") label(2 "Leave") rows(2)) xtitle("Property Wealth") title(" ") note(" ")
graph export "$output/fig_c21.pdf", replace
qui ksmirnov z_p_wealth, by(leave) 


kdensity z_f_wealth if leave == 0, plot(kdensity z_f_wealth if leave == 1, lpattern("solid") lcolor("orange")) ///
	legend(label(1 "Remain") label(2 "Leave") rows(2))	  xtitle("Property Wealth") title(" ") note(" ")
graph export "$output/fig_c22.pdf", replace
ksmirnov z_f_wealth, by(leave) 
restore

*************
* Figure C3
*************

********************************************************************************

** who's wealthy?

preserve
graph bar z_p_wealth, over(female,  relabel(1 "Male" 2 "Female"))  ytitle("Mean Property Wealth")   
graph export "$output/fig_c3_des1.pdf", replace
graph bar z_p_wealth, over(married, relabel(1 "Not Married" 2 "Married")) ytitle("Mean Property Wealth") 
graph export "$output/fig_c3_des2.pdf", replace
twoway (scatter z_p_wealth  ageW14,  msymbol(Uh) msize(2.5) mcolor(gs13%30)) (lfit z_p_wealth ageW14, lcolor("red") )  , legend(off) ytitle("Mean Property Wealth")
graph export "$output/fig_c3_des3.pdf", replace
graph bar z_p_wealth, over(anyUniW14, relabel(1 "No" 2 "Enrolled" 3 "Left HE" 4 "Yes"))  ytitle("Mean Property Wealth") b1title("Higher Education")  
graph export "$output/fig_c3_des4.pdf", replace
graph bar z_p_wealth , over(wkstat, relabel(1 "Employed" 2 "Unemployed" 3 "Student" 4 "Retired" 5 "Out of Labour Force"))  ytitle("Mean Property Wealth")
graph export "$output/fig_c3_des5.pdf", replace


graph bar z_f_wealth, over(female,  relabel(1 "Male" 2 "Female"))  ytitle("Mean Financial Wealth") 
graph export "$output/fig_c4_des1.pdf", replace
graph bar z_f_wealth, over(married, relabel(1 "Not Married" 2 "Married")) ytitle("Mean Financial Wealth") 
graph export "$output/fig_c4_des2.pdf", replace
twoway (scatter z_f_wealth  ageW14,msymbol(Uh) msize(2.5) mcolor(gs13%30)) (lfit z_f_wealth ageW14, lcolor("red")) , legend(off) ytitle("Mean Financial Wealth")
graph export "$output/fig_c4_des3.pdf", replace
graph bar z_f_wealth, over(anyUniW14, relabel(1 "No" 2 "Enrolled" 3 "Left HE" 4 "Yes"))  ytitle("Mean Financial Wealth") b1title("Higher Education")  
graph export "$output/fig_c4_des4.pdf", replace
graph bar z_f_wealth , over(wkstat, relabel(1 "Employed" 2 "Unemployed" 3 "Student" 4 "Retired" 5 "Out of Labour Force"))  ytitle("Mean Financial Wealth")
graph export "$output/fig_c4_des5.pdf", replace
restore

*************
* Figure D1
*************

preserve
besw14b
bwealth

gen homevalueDK = 1 if homevalue == .
replace homevalueDK = 0 if homevalue!=.

gen f_wealth = mean_save - mean_debt
gen incomerent2 = mean_income - yearly_rent - yearly_mortgage

gen incomedisHH2 = incomerent2/HHsize
gen f_wealthHH = f_wealth / HHsize

egen z_income_disHH = std(incomedisHH2)
egen z_f_wealth = std(f_wealthHH)

qui reg leave z_income_disHH z_f_wealth $cfe  homevalueDK   , r
regsave  using "$temp/figd1data", replace   ci
restore
